import React, {Component} from 'react';
import {Popconfirm, Button, Icon} from 'antd';
import noop from 'util/noop';


export default class ReceiptButton extends Component {
    static defaultProps = {
        visible: false,
        loading: false,

        onConfirm: noop,
        onCancel: noop,
        changeVisible: noop
    }


    constructor(props) {
        super(props);
        this.title = ["确定收款吗？", "订单收款中，请稍等..."];
        this.okText = ["确定", <Icon type="loading"><span className="ml5">确定</span></Icon>];
        this.state = {
            loading: false
        }
    }


    render() {
        const {visible, loading} = this.props;

        return (
            <Popconfirm placement="left"
                        visible={visible}
                        title={this.title[Number(loading)]}
                        okText={this.okText[Number(loading)]}
                        onConfirm={this.onConfirm}
                        onCancel={this.onCancel}>
                <Button type="primary" className="pushl" onClick={this.changeVisible}>收款</Button>
            </Popconfirm>
        )
    }


    onConfirm = ()=>{
        this.props.onConfirm();
    }


    onCancel = ()=>{
        this.props.onCancel();
    }


    changeVisible = ()=>{
        this.props.changeVisible();
    }
}